package com.invengo.module_check.data.repsitory.offlinedata.source;

import com.invengo.library_db.GreenDaoManager;
import com.invengo.library_db.entity.module_check.BookBean;
import com.invengo.library_db.entity.module_check.offline.BookJson;
import com.invengo.library_db.entity.module_check.ColumBean;
import com.invengo.library_db.entity.module_check.offline.FlowBean;
import com.invengo.library_db.entity.module_check.ShelfBean;
import com.invengo.library_db.entity.module_check.ShelfJson;
import com.invengo.library_db.entity.module_check.StructBean;
import com.invengo.library_db.entity.module_check.offline.UserBean;

import java.util.List;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.http.BaseBean;
import me.goldze.mvvmhabit.http.UpdateResult;

public interface NetModelSource {
    /**
     * 获取所有用户
     *
     * @return {@link Observable}<{@link BaseBean}<{@link List}<{@link UserBean}>>>
     */
    Observable<BaseBean<List<UserBean>>> getAllUser();

    /**
     * get结构
     *
     */
    public Observable<BaseBean<List<StructBean>>> getStruct();

    /**
     * 获取所有图层
     *
     * @return {@link Observable}<{@link BaseBean}<{@link ShelfJson}>>
     */
    public Observable<BaseBean<ShelfJson>> getAllShelf();

    /**
     * 获取图书计数
     *
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @return {@link Observable}<{@link BaseBean}<{@link Long}>>
     */
    Observable<BaseBean<Long>> getBookCount(String beginTime, String endTime);

    /**
     * 获取书本分页数据
     *
     * @param pageIndex 页面索引
     * @param pageSize  页面大小
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @return {@link Observable}<{@link BaseBean}<{@link ShelfJson}>>
     */
    Observable<BaseBean<BookJson>> getPagingDataOfBook(int pageIndex, int pageSize, String beginTime, String endTime);

    /**
     * 获取书本分页数据  山东大学使用的接口
     *
     * @param pageIndex 页面索引
     * @param pageSize  页面大小
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @return {@link Observable}<{@link BaseBean}<{@link ShelfJson}>>
     */
    Observable<BaseBean<BookJson>> getPagingDataOfBook(String pageIndex, String pageSize, String beginTime, String endTime);

    /**
     * 保存用户2数据库
     *
     * @param userBeans rfid用户
     */
    default void saveUser2DB(List<UserBean> userBeans) {
        GreenDaoManager.getInstance().insertUser2DB(userBeans);
    }

    /**
     * 插入自身信息
     *
     * @param shelfInfoBeans 货架信息豆
     * @return boolean
     */
    default boolean insertSelfInfo(List<ShelfBean> shelfInfoBeans) {
        GreenDaoManager.getInstance().insertSelfInfo(shelfInfoBeans);
        return true;
    }

    default  boolean insertCoumBneas(List<ColumBean> columBeans) {
        GreenDaoManager.getInstance().insertCoumBneas(columBeans);
        return true;
    }

    /**
     * 保存书本2数据库
     *
     * @param bookBeans 书豆
     */
    default void saveBooks2DB(List<BookBean> bookBeans) {
        GreenDaoManager.getInstance().saveBooks2DB(bookBeans);
    }

    /**
     * 清除用户数据
     */
    default void cleanUserData() {
        GreenDaoManager.getInstance().cleanUserData();
    }

    /**
     * 清除图层数据
     */
    default void cleanLayerData() {
        GreenDaoManager.getInstance().cleanShelfData();
    }

    /**
     * 清理账簿数据
     */
    default void cleanBookData() {
        GreenDaoManager.getInstance().cleanBookData();
    }

    /**
     * 清除所有基本数据
     */
    default void cleanAllBaseData() {
        GreenDaoManager.getInstance().cleanBookData();
        GreenDaoManager.getInstance().cleanShelfData();
        GreenDaoManager.getInstance().cleanUserData();
    }

    /**
     * 清除所有业务数据
     */
    default void cleanAllBusinessData() {
        GreenDaoManager.getInstance().cleanBusinessData();
    }

    /**
     * 具有脱机数据
     *
     * @return boolean
     */
    default boolean isHaveOfflineData() {
        return getShelfCountFromDB() > 0 && getBookCountFromDB() > 0;
    }

    /**
     * 从数据库获取图书计数
     *
     * @return {@link Long}
     */
    default Long getBookCountFromDB() {
        return GreenDaoManager.getInstance().getBookCountFromDB();
    }

    /**
     * 从数据库获取用户计数
     *
     * @return {@link Long}
     */
    default Long getUserCountFromDB() {
        return GreenDaoManager.getInstance().getUserCountFromDB();
    }

    /**
     * 从数据库获取层计数
     *
     * @return {@link Long}
     */
    default Long getShelfCountFromDB() {
        return GreenDaoManager.getInstance().getShelfCount();
    }

    default List<ShelfBean> getAllShelfFromDB(){
        return GreenDaoManager.getInstance().getAllShelfs();
    }

    default Integer getBusinessCountFromDB() {
        return GreenDaoManager.getInstance().getBusinessCount();
    }


    List<FlowBean> getBusinessData();
    Observable<BaseBean<UserBean>> checkLogin(String account, String password);

    Observable<BaseBean<UpdateResult>> uploadData(FlowBean bean);

    void deleteBusinessBean(FlowBean bean);

    void saveStruct2DB(List<StructBean> collect);

    List<StructBean> getStructData();

    void removeAllColum();

    Long getAllColumCount();

    List<ColumBean> getColumData(StructBean bean);

    StructBean getStructByShelf(ShelfBean bean);
}
